<template>
  <div class="list_bg">
    <div class="good_section" v-for="(item) in handleData" :key="item.id">
      <div class="good_bg" v-for="(good,index) in item" :key="index" @click="handleDetail(good)">
        <div class="img_bg">
          <img :src="good.image" alt="">
        </div>
        <div class="good_name">{{ good.name }}</div>
        <div class="good_price_bg" v-if="userInfo.status === 1">
          <div class="good_price">￥{{ good.priceText }}</div>
          <!-- <div class="good_sale_num">销量：{{ good.saleNum }}</div> -->
        </div>
        <div v-else class="info">企业注册认证后查看价格</div>
      </div>
    </div>
  </div>
</template>

<script>
import {mapGetters} from "vuex";

export default {
  name: 'ProductList',
  props: {},
  components: {

  },
  props: {
    list: {
      type: Array,
      default: () => []
    },
  },
  data() {
    return {
      
    }
  },
  computed: {
    ...mapGetters(["userInfo"]),
    handleData() {
      let index =0;
      let count = 5;
      let arrTemp = [];
      let experts = this.list;
      for(let i=0;i<this.list.length;i++){
        index = parseInt(i/count);
        if (arrTemp.length <= index) {
            arrTemp.push([]);
        }
        arrTemp[index].push(experts[i])
      }
      return arrTemp
    }
  },
  watch: {},
  methods: {
    handleDetail(item) {
      this.$emit("handleDetail", item);
    }
  },
  created() {
    
  },
  mounted() {
    
  },
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
}
</script>

<style lang='scss' scoped>
  .list_bg {
    width: 100%;
    background-color: rgb(243, 245, 249);
  }

  .good_section {
    width: 100%;
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;

    &:nth-child(1) {
      margin-top: 0px;
    }
  }
  .good_bg {
    width: 248px;
    height: 310px;
    border: 1px solid white;
    box-sizing:border-box;
    margin-left: 15px;
    background: #fff;
    
    &:nth-child(5n+ 1) {
      margin-left: 0px;
    }
    &:hover,
    &:focus,
    &:visited {
      // box-shadow: 0 0 5px 1px rgba(252, 38, 38, 1);
      border: 1px solid rgba(252, 38, 38, 1);
      cursor: pointer;
    }

    .img_bg {
      margin-left: 34px;
      margin-top: 25px;
      width: 180px;
      height: 180px;

      img {
        width: 100%;
        height: 100%;
        border-radius: 8px;
      }
    }

    .good_name {
      margin-top: 25px;
      margin-left: 22px;
      width: 201px;
      height: 18px;
      color: rgba(51, 51, 51, 1);
      font-size: 14px;
      font-weight: 400;
      line-height: 18px;
      @include ellipsis($line: 1);
    }

    .good_price_bg {
      display: flex;
      justify-content: space-between;
      margin-top: 11px;
      margin-left: 22px;
      width: 201px;
      height: 26px;

      .good_price {
        color: rgba(252, 38, 38, 1);
        font-size: 14px;
        font-weight: 400;
        line-height: 26px;
        @include ellipsis($line: 1);
      }
      .good_sale_num {
        color: rgba(51, 51, 51, 1);
        font-size: 14px;
        font-weight: 400;
        line-height: 26px;
        @include ellipsis($line: 1);
      }
    }

    .info {
      margin-top: 9px;
      margin-left: 22px;
      width: 152px;
      height: 28px;
      color: rgba(115, 133, 156, 1);
      font-size: 12px;
      font-weight: 400;
      line-height: 28px;
      text-align: center;
      background: rgba(218, 224, 232, 1);
      border-radius: 2px;
    }
  }

  
</style>